<template>
  <div>
    <router-link to="/category/add">
    <el-button type="primary">
        <i class="el-icon-circle-plus-outline"></i>添加
    </el-button>
    </router-link>
    <div class="bgf">
        <!-- 列表 -->
        <el-table :data="list" row-key="id" :tree-props="{ hasChildren: 'hasChildren', children: 'children' }">
            <el-table-column prop="id" label="ID" ></el-table-column>
            <el-table-column prop="catename" label="分类名称" >
                <template slot-scope="scope">
                    <span v-if="scope.row.pid==0">{{scope.row.catename}}</span>
                    <span v-else>&nbsp;&nbsp;&nbsp;&nbsp;{{scope.row.catename}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="img" label="分类图片" >
                <template slot-scope="scope">
                     <img :src="$HOST+scope.row.img" class="picimg" alt="">
                </template>
            </el-table-column>
            <el-table-column prop="status" label="状态" >
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.status">已启用</el-tag>
                    <el-tag type="danger" v-else>已禁用</el-tag>  
                </template>
            </el-table-column>
            <el-table-column label="操作"  align="center">
                <template slot-scope="scope">
                      <router-link :to="'/category/'+scope.row.id"><el-button type="success" icon="el-icon-edit" size="mini" circle  ></el-button></router-link>
                      <el-button type="danger" icon="el-icon-delete" size="mini" @click="delRow(scope.row.id)" circle></el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
  </div>
</template>

<script>
// 获取数据、删除数据
import { getCategory,delCategory } from "@/request/category"
export default {
    data(){
        return{
            list:[],
        }
    },
    created(){
        this.getlist();  // 获取列表
    },
    methods:{
        async getlist(){
            this.list = await getCategory();  //  获取树形数据！
        },
        delRow(id){  // 删除某一条数据，接收删除的ID
            // 弹框确认！
            this.$confirm('确定删除吗, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                // 删除功能！
                await delCategory(id);
                this.getlist();
            })
        }
    },
    components:{
    }
}

</script>
<style scoped>
.picimg{
    width:60px;
    border:1px solid #eee;
}
</style>